<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: WebAPI::JsonParser</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">WebAPI::JsonParser</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/webapi/json_rb.html">
                webapi/json.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h1>Simple JSON parser</h1>
<p>
This class converts a JSON string to an array or a hash. If <b>json_str</b>
contains a JSON form string, you can convert it like below.
</p>
<pre>
  ruby_obj = WebAPI::JsonParser.new.parse(json_str)
</pre>
<p>
If <b>json_str</b> has one or more invalid UTF-8 sequence, <a
href="JsonParser.html">JsonParser</a> throws exception by default. You can
change this behavior to replacing with an arbitrary unicode character. See
below for details.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000004">new</a>&nbsp;&nbsp;
      <a href="#M000005">parse</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a <a href="JsonParser.html#M000004">new</a> instance of <a
href="JsonParser.html">JsonParser</a>. <b>options</b> can contain these
values.
</p>
<dl>
<dt>:validation</dt><dd>If set to false, UTF-8 validation is disabled. true by default.

</dd>
<dt>:surrogate</dt><dd>If set to false, surrogate pair support is disabled. true by default.

</dd>
<dt>:malformed_chr</dt><dd>An invalid sequence in JSON string will be replaced with this value. If set
to nil, An exception will be thrown in this situation. nil by default.

</dd>
</dl>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
    <span class="ruby-comment cmt"># File webapi/json.rb, line 53</span>
53:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
54:       <span class="ruby-ivar">@default_validation</span>    = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:validation</span>)    <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:validation</span>]    <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>
55:       <span class="ruby-ivar">@default_surrogate</span>     = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:surrogate</span>)     <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:surrogate</span>]     <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>
56:       <span class="ruby-ivar">@default_malformed_chr</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:malformed_chr</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:malformed_chr</span>] <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
57:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">parse</span><span class="method-args">(str, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convert <b>str</b> to an array or hash.
</p>
<dl>
<dt>str</dt><dd>A JSON form string. This must be encoded using UTF-8.

</dd>
<dt>options</dt><dd>Same as <a href="JsonParser.html#M000004">new</a>.

</dd>
</dl>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
    <span class="ruby-comment cmt"># File webapi/json.rb, line 64</span>
64:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">options</span> = {})
65:       <span class="ruby-ivar">@enable_validation</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:validation</span>)    <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:validation</span>]    <span class="ruby-operator">:</span> <span class="ruby-ivar">@default_validation</span>
66:       <span class="ruby-ivar">@enable_surrogate</span>  = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:surrogate</span>)     <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:surrogate</span>]     <span class="ruby-operator">:</span> <span class="ruby-ivar">@default_surrogate</span>
67:       <span class="ruby-ivar">@malformed_chr</span>     = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:malformed_chr</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:malformed_chr</span>] <span class="ruby-operator">:</span> <span class="ruby-ivar">@default_malformed_chr</span>
68:       <span class="ruby-ivar">@malformed_chr</span> = <span class="ruby-ivar">@malformed_chr</span>[<span class="ruby-value">0</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-constant">String</span> <span class="ruby-operator">===</span> <span class="ruby-ivar">@malformed_chr</span>
69:       <span class="ruby-ivar">@scanner</span> = <span class="ruby-constant">StringScanner</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">str</span>)
70:       <span class="ruby-identifier">obj</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">get_symbol</span>[<span class="ruby-value">0</span>]
71:             <span class="ruby-keyword kw">when</span> <span class="ruby-value">?{</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">parse_hash</span>
72:             <span class="ruby-keyword kw">when</span> <span class="ruby-value">?[</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">parse_array</span>
73:             <span class="ruby-keyword kw">else</span>         <span class="ruby-identifier">raise</span> <span class="ruby-identifier">err_msg</span>(<span class="ruby-constant">ERR_IllegalSyntax</span>)
74:             <span class="ruby-keyword kw">end</span>
75:       <span class="ruby-ivar">@scanner</span> = <span class="ruby-keyword kw">nil</span>
76:       <span class="ruby-identifier">obj</span>
77:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>